// pages/index/government_affairs/government_affairs.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    result: [],
    pageTotalNumber: 0,
    options: ["待审事项", "待议事项", "已完成"],
    activeIndex:0,
    formPage:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: app.globalData.appTitle,
    })
    this.setData({
      theme: app.globalData.theme
    });
    app.setNavigationBarColor();
    app.globalData.pageNumber = 1;
    this.govermmentAffairsLoad();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.formPage=="add"){
      this.setData({
        formPage: "",
        result:[]
      });
      app.globalData.pageNumber = 1;
      this.govermmentAffairsLoad();
      
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    app.globalData.pageTotalNumber = 0;
    app.globalData.pageNumber = 1;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 详情
   */
  govemmentAffairsDetail: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/"pages/index/government_affairs/government_affairs_detail/government_affairs_detail?id=' + id,
    })
  },
  /**
   * 切换
   */
  handleScrollableChange: function (e) {
    let value = e.detail.value;
    this.setData({
      activeIndex: value
    });
    app.globalData.pageNumber = 1;
    this.setData({
      result: []
    });
    this.govermmentAffairsLoad();
  },
  /**
   * 默认加载
   */
  govermmentAffairsLoad: function () {
    app.wxGetRequest("/wechart/life/getMicroservice", {
      area_code: app.globalData.parentAreaCode,
      url: app.globalData.urlMicro + "/v1/conferences",
      page_number: app.globalData.pageNumber,
      page_size: app.globalData.pageSize,
      is_type: this.data.activeIndex,
      type:1
    }).then(result => {
      let pageTotalNumber = Math.ceil(result.data.count / app.globalData.pageSize)
      this.setData({
        result: this.data.result.concat(result.data.records),
        ["noData" + this.data.activeIndex]: pageTotalNumber == 0 ? true : false,
        mpLoadingShow: false
      });
      app.globalData.pageTotalNumber = pageTotalNumber;
    });
  },
  /**
   * 滚动底部架加载
   */
  handleLoadmore: function () {
    app.globalData.pageNumber++;
    this.setData({
      mpLoadingShow: true,
      mpLoadingTips: "加载中..."
    });
    if (app.globalData.pageNumber <= app.globalData.pageTotalNumber) {
      this.govermmentAffairsLoad();
    } else {
      setTimeout(() => {
        this.setData({
          mpLoadingTips: "暂无数据"
        });
      }, 500);
      setTimeout(() => {
        this.setData({
          mpLoadingShow: false
        });
      }, 1000);
    }
  },
  /**
   * 发布议事
   */
  addBusinessHall:function(){
    app.isVerifiedAuth("/pages/index/business_hall/add_business_hall/add_business_hall");
  },
  /**
   * 详情
   */
  businessHallDetail:function(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/business_hall/business_hall_detail/business_hall_detail?id='+id,
    })
  }
})